package com.dq.controller;

import com.dq.pojo.CarInsurance;
import com.dq.service.Impl.CarInsuranceServiceImpl;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import io.swagger.annotations.Api;

import javax.annotation.Resource;

/**
 * (CarInsurance)表控制层
 *
 * @author thinknovo
 * @since 2024-01-18 20:00:42
 */
@RestController
@RequestMapping("carInsurance")
@Api(value = "(CarInsurance)",tags = "(CarInsurance)接口API")
public class CarInsuranceController {
    /**
     * 服务对象
     */
    @Resource
    private CarInsuranceServiceImpl carInsuranceServiceImpl;

    /**
     * 一次性全部查询
     *
     * @return 查询结果
     */
//    @GetMapping("/selectAll")
    public Map<String, Object> selectAll() {
        return carInsuranceServiceImpl.selectAll();
    }

    /**
     * 分页查询
     *
     * @param carInsurance 筛选条件
     * @param page        要查询第几页
     * @param limit       每页显示多少条
     * @return 查询结果
     */
    @GetMapping("")
    public Map<String, Object> selectByLimit(@RequestParam String carNumber, @RequestParam int page, @RequestParam int limit) {
        CarInsurance carInsurance1 = new CarInsurance();
        carInsurance1.setCarNumber(carNumber);
        return carInsuranceServiceImpl.selectByLimit(carInsurance1, page, limit);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
//    @GetMapping("/selectById")
    public Map<String, Object> selectById(@RequestParam Integer id) {
        return carInsuranceServiceImpl.selectById(id);
    }

    /**
     * 新增数据
     *
     * @param carInsurance 实体
     * @return 新增结果
     */
    @PostMapping("")
    public Map<String, Object> insert(@RequestBody CarInsurance carInsurance) {
        return carInsuranceServiceImpl.insert(carInsurance);
    }

    /**
     * 编辑数据
     *
     * @param carInsurance 实体
     * @return 编辑结果
     */
    @PutMapping("")
    public Map<String, Object> updateById(@RequestBody CarInsurance carInsurance) {
        return carInsuranceServiceImpl.updateById(carInsurance);
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/{id}")
    public Map<String, Object> deleteById(@PathVariable Integer id) {
        return carInsuranceServiceImpl.deleteById(id);
    }

}

